package cn.itsource.blog.controller;

import cn.itsource.blog.dto.LoginDto;
import cn.itsource.blog.service.ILogininfoService;
import cn.itsource.exception.BusinessException;
import cn.itsource.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class LoginController {

    @Autowired
    private ILogininfoService loginInfoService;

    @PostMapping("/login")
    public JsonResult login(@RequestBody LoginDto loginDto){
        try{

            String token = loginInfoService.login(loginDto);
            return JsonResult.success(token);
        }catch (BusinessException e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }catch (Exception e){
            e.printStackTrace();
            return JsonResult.error(e.getMessage());
        }

    }
}
